package com.deco.logic.store;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.deco.dao.delegate.store.IStoreShopDao;
import com.deco.domain.vo.store.StoreShopVo;
import com.free.common.vo.PageResponseVo;
import com.free.common.vo.PageSearchVo;

/**
 * <p>
 * 功能概述:
 * </p>
 * <p>
 * 功能详述:
 * </p>
 */
@Component
public class StoreShopLogic {
    /*========================================================================*
     *                         Public Fields (公共属性)
     *========================================================================*/

    /*========================================================================*
     *                         Private Fields (私有属性)
     *========================================================================*/
    
    @Autowired
    IStoreShopDao storeShopDao;

    /*========================================================================*
     *                         Construct Methods (构造方法)
     *========================================================================*/

    /*========================================================================*
     *                         Public Methods (公有方法)
     *========================================================================*/

	public StoreShopVo getStoreShop(int id) {
		StoreShopVo storeShopVo = new StoreShopVo();
		storeShopVo.setId(id);
		return storeShopDao.selectOne(storeShopVo);
	}

	@CacheEvict(value = "storeShopCache",allEntries = true)
	public void create(StoreShopVo storeShopVo) {
		storeShopDao.add(storeShopVo);
		
	}

	@CacheEvict(value = "storeShopCache",allEntries = true)
	public void update(StoreShopVo storeShopVo) {
		storeShopDao.update(storeShopVo);
		
	}

	@CacheEvict(value = "storeShopCache",allEntries = true)
	public void delete(int id) {
		storeShopDao.delete(id);
	}

	public PageResponseVo<StoreShopVo> getPageInfo(
			PageSearchVo<StoreShopVo> condition) {
		return storeShopDao.selectByPageNoNameLike(condition.getConditionVo(), " create_time desc ", condition.getCurrentNo(), condition.getLength());
	}

	@CacheEvict(value = "storeShopCache",allEntries = true)
	public int batchDelete(Integer[] ids) {
		return storeShopDao.batchDelete(ids);
	}

	@Cacheable(value="storeShopCache", key = "#type")
	public List<StoreShopVo> queryProvList(Integer type) {
		// TODO Auto-generated method stub
		return storeShopDao.queryProvList(type);
	}

	@Cacheable(value="storeShopCache", key = "T(String).valueOf(#type).concat('-').concat(#prov)")
	public List<StoreShopVo> queryCityList(Integer type, String prov) {
		// TODO Auto-generated method stub
		return storeShopDao.queryCityList(type,prov);
	}

	@Cacheable(value="storeShopCache", key = "T(String).valueOf(#type).concat('-').concat(#city)")
	public List<StoreShopVo> queryAreaList(Integer type, String city) {
		// TODO Auto-generated method stub
		return storeShopDao.queryAreaList(type,city);
	}

	public List<StoreShopVo> queryStoreShop(StoreShopVo shop) {
		// TODO Auto-generated method stub
		return storeShopDao.selectByNameLike(shop, " create_time desc ");
	}

    /*========================================================================*
     *                         Private Methods (私有方法)
     *========================================================================*/
}
